package cn.seqdata.tree;

import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;

import cn.seqdata.jpa.JpaNamed;

public class NamedTreeNode<ID extends Serializable, T extends JpaNamed<ID>> extends TreeNode {
	protected final T wrapper;

	/** 默认添加容器节点 */
	public NamedTreeNode(T object) {
		super(false);

		this.wrapper = object;
	}

	@JsonIgnore
	public T getWrapper() {
		return wrapper;
	}

	/** 默认添加容器节点 */
	public NamedTreeNode(T object, boolean container) {
		super(container);
		this.wrapper = object;
	}

	public NamedTreeNode(T object, boolean container, boolean expaned) {
		super(container, expaned);
		this.wrapper = object;
	}

	@Override
	public String getId() {
		return String.valueOf(wrapper.getId());
	}

	@Override
	public String getText() {
		return StringUtils.isEmpty(wrapper.getName()) ? String.valueOf(getId()) : wrapper.getName();
	}

	@Override
	public String getClz() {
		return wrapper.getClass()
			.getSimpleName();
	}
}
